<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Sinbiota.Web.Models.EditUserModel>" %>
<%@ Import Namespace="Localization" %>
<%@ Import Namespace="SinBiota.Model.Entities" %>
<%@ Import Namespace="Sinbiota.Web.Extensions" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%: Strings.EditUser %>    
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2> <%: Strings.EditUser %>   </h2>
    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(false) %>    
    <fieldset>
        <div class="display-label">
            <%: Strings.Username %>: 
        </div>
        <div class="display-field">
            <%: Model.Username %>
        </div>

        <%: Html.EditorForModel() %>
        
        <div class="editor-label">
            <%: Strings.Role %>
        </div>
        <div class="editor-field">
        <%: Html.EnumDropDownList<Role>() %>
        </div>
        <div class="editor-label"><%: Strings.Projects %></div>
        <div class="editor-field">
        <i><%: Strings.Coordinator %>:</i><span id="CoordinatorField"></span>
        </div>
        <div class="editor-field">
        <i><%: Strings.Member %>:</i><span id="MemberField"></span>
        </div>
        <div class="editor-label">
        <%: Strings.AddProject %>
        </div>        
        <div class="editor-field">
            <select id="ProjectId" name="ProjectId"><option value="0"></option></select><img id="ProjectSelectWaiting" src='<%: Url.WaitingImage() %>' alt="Busy" style="display:none;"/>
        </div>        
        <div>
            <button id="AddAsCoordinator" class="small radius red button"><%: Strings.AddAsCoordinator %></button>
            <button id="AddAsMember" class="small radius red button"><%: Strings.AddAsMember %></button>
        </div>        

        
    </fieldset>
        <p>
            <input type="submit" value="Save" />
        </p>


    <%
}%>
    <div class="small button radius">
        <%: Html.ActionLink(Strings.BackToList, "Index") %>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Role").val('<%: (int) Enum.Parse(typeof(Role),Model.Role.ToString()) %>');
        });
    </script>

<%-- SCRIPTS --%>
<script type="text/javascript" src="<%: Url.Content("~/Scripts/Custom/BiotaAjaxFunctions.js") %>"></script>
<script type="text/javascript">
    // Array to store words for the keyword list
    var CoordinatorField = new Array();
    var MemberField = new Array();
    //Initializations: 
    $(document).ready(function () {
        //InitProjectList: needed when editing an existing user:
        InitProjectList();
        // populate project dropdown:
        populateSelect('Project');
        // init buttons:
        $("#AddAsCoordinator").click(function() { 
            AddWord($("#ProjectId option:selected").text(), "Coordinator");
            return false;
         });
        $("#AddAsMember").click(function() { 
            AddWord($("#ProjectId option:selected").text(), "Member");
            return false;
         });
    });
    function InitProjectList() {
    <% if (Model != null && Model.CoordinatorProjects!= null)
        foreach (var project in Model.CoordinatorProjects.Select(k => k.Name))
    { %>
        AddWord('<%: project %>','Coordinator');
    <% } %>        
    <% if (Model != null && Model.MemberProjects!= null)
        foreach (var project in Model.MemberProjects.Select(k => k.Name))
    { %>
        AddWord('<%: project %>','Member');
    <% } %>        

    }

</script>


</asp:Content>
